package com.yex.service.modify.merchant;

import com.yex.common.exception.RRException;
import com.yex.dao.UserDao;
import com.yex.entity.UserEntity;
import com.yex.service.modify.BaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;

@Service
@Transactional
public class ApiMerchantService extends BaseService<UserDao, UserEntity> {

    public String register(UserEntity userEntity, HttpServletRequest request) {
        UserEntity userEntity1 = validateLoginUser(request);
        if (userEntity1.getMerchantState() != 0) {
            if (userEntity1.getMerchantState() == 1) {
                throw new RRException("商户审核中,请勿重复申请!");
            } else {
                throw new RRException("您已是商户,请勿重复申请!");
            }
        }
        userEntity.setId(userEntity1.getId());
        userEntity.setMerchantState(1);
        baseMapper.updateMerchantInfo(userEntity);
        return "申请商户成功";
    }

}
